package com.dataclean.lk

import org.apache.spark.sql.SparkSession

object OrdersClean {


  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("OrdersClean")
      .config("spark.sql.warehouse.dir","hdfs://master:9000/user/hive/warehouse")
      .enableHiveSupport()
      .getOrCreate()

    spark.sqlContext.sql("use ods")

    val hiveDF = spark.sqlContext.sql(
      """
        |select
        |*
        |from
        |orders_lk
        |""".stripMargin)

    hiveDF.createOrReplaceTempView("orders_lk_hive")

    spark.sqlContext.sql(
      """
        |insert overwrite table dwd.orders_lk
        |(
        |select
        |distinct
        |ORDERKEY,
        |CUSTKEY,
        |ORDERSTATUS,
        |TOTALPRICE,
        |date_format(ORDERDATE,'yyyy-MM-dd HH:mm:ss') as ORDERDATE,
        |ORDERPRIORITY,
        |CLERK,
        |SHIPPRIORITY,
        |COMMENT
        |from orders_lk_hive
        |)
        |""".stripMargin)



  }

}
